import { Component, Input, Output, EventEmitter, OnInit, OnChanges } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular';
import { DatePipe } from '@angular/common';
// import { isNumber } from '@ionic/angular/umd/util/util';

@Component({
    selector: 'leader-to',
    templateUrl: './leader-to.html'
})
export class LeaderToPage implements OnInit, OnChanges {
    title;         // 上一页面传递的参数
    departcode;
    options;       // 环形图参数
    nowDate;
    departs;       // 获取页面数据
    where = null;

    constructor(public modalCtrl: ModalController, private datePipe: DatePipe, private navParams: NavParams) {
        this.nowDate = this.datePipe.transform(new Date(), 'yyyy-MM-dd');
    }

    ngOnInit() {
        this.title = this.navParams.get('title');
        this.departcode = this.navParams.get('departcode');
        this.options = {
            bgColor: '#E8F7FF',
            elWidth: 68,
            elHeight: 68,
            levelColor: '#1fb5ff',
            lineWidth: 4,
            Num: 5
        };
        this.departs = [{
            total: 30,
            companys: 20,
            DeptName: '平台研发',
            outs: 5,
            leaves: 4,
            abnormals: 1,
            info: [{
                UserName: '小马',
                startTime: '2018-11-23',
                endTime: '2019-1-12',
                state: '异常'
            }]
        },
        {
            total: 40,
            companys: 20,
            DeptName: '平台研发',
            outs: 5,
            leaves: 4,
            abnormals: 1,
            info: [{
                UserName: '小马',
                startTime: '2018-11-23',
                endTime: '2019-1-12',
                state: '异常'
            }]
        },
        {
            total: 50,
            companys: 20,
            DeptName: '平台研发',
            outs: 5,
            leaves: 4,
            abnormals: 1,
            info: [{
                UserName: '小马',
                startTime: '2018-11-23',
                endTime: '2019-1-12',
                state: '请假'
            }]
        },
        {
            total: 30,
            companys: 20,
            DeptName: '平台研发',
            outs: 5,
            leaves: 4,
            abnormals: 1,
            info: [{
                UserName: '小马',
                startTime: '2018-11-23',
                endTime: '2019-1-12',
                state: '正常'
            }]
        }];
    }

    aim(i) {
    }

    toVideo() {
    }

    ngOnChanges() {
        for (let i = 0; i < this.departs.length; i++) {
            this.departs[i].shown = false;
        }
    }

    changeDate(i) {
        const addDate = new Date(this.nowDate);
        if (i === 1) {
            addDate.setDate(new Date(this.nowDate).getDate() + 1);
        } else {
            addDate.setDate(new Date(this.nowDate).getDate() - 1);
        }
        this.nowDate = this.datePipe.transform(addDate, 'yyyy-MM-dd');
        this.getInitData(this.nowDate);
    }

    getInitData(time) {
        console.log(time);
    }

    toggle(i) {
        if (i === this.where) {
            this.departs[i].shown = !this.departs[i].shown;
        } else if (typeof(this.where) === 'number') {
            this.departs[this.where].shown = false;
            this.departs[i].shown = true;
        } else {
            this.departs[i].shown = true;
        }
        this.where = i;
    }
}
